<!DOCTYPE html>
<html class="x-admin-sm">

<head>
<meta charset="UTF-8">
<title>欢迎页面-X-admin2.2</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
<link rel="stylesheet" href="./css/font.css">
<link rel="stylesheet" href="./css/xadmin.css">
<script src="./lib/layui/layui.js" charset="utf-8"></script>
<script type="text/javascript" src="./js/xadmin.js"></script>
          <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
          <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
			<script src="js/jquery-3.4.1.min.js"></script>
</head>

<body>
	<div class="x-nav">
		<span class="layui-breadcrumb"> <a href="index.html">首页</a> <a href="">管理员</a>
			<a> <cite>项目列表</cite></a>
		</span> <a class="layui-btn layui-btn-small"
			style="line-height: 1.6em; margin-top: 3px; float: right"
			onclick="location.reload()" title="刷新"> <i
			class="layui-icon layui-icon-refresh" style="line-height: 30px"></i>
		</a>
	</div>
	<div class="layui-fluid">
		<div class="layui-row layui-col-space15">
			<div class="layui-col-md12">
				<div class="layui-card">
					<div class="layui-card-body "><form class="layui-form layui-col-space5">
                        <div class="layui-inline layui-show-xs-block">
                            <input class="layui-input" autocomplete="off" placeholder="项目名"
                                   name="name" id="name">
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <input class="layui-input" autocomplete="off" placeholder="分类"
                                   name="category" id="category">
                        </div>

                        <div class="layui-inline layui-show-xs-block">
                            <button class="layui-btn" lay-submit lay-filter="sreach">
                                <i class="layui-icon">&#xe615;</i>
                            </button>
                        </div>
                    </form>
					</div>
				<!--	<div class="layui-card-body ">
						<table class="layui-table" width="100%"
							lay-data="{url:'projectSearch',page:true,toolbar: '#toolbarDemo',id:'queryTable'}"
							lay-filter="queryTable">
							<thead>
								<tr>
									<th lay-data="{type:'checkbox'}">ID</th>
									<th lay-data="{field:'id', width:80, sort: true}">编号</th>
									<th lay-data="{field:'projectName', width:120, sort: true, edit: 'text'}">项目名称</th>
									<th lay-data="{field:'projectCategory', edit: 'text', minWidth: 90}">项目类型</th>
									<th lay-data="{field:'professorNum', edit: 'text', minWidth: 80}">专家人数</th>
									<th lay-data="{field:'isEvaluated', sort: true, edit: 'text', minWidth: 100}">项目状态</th>
									<th lay-data="{field:'prochaseMode', sort: true, edit: 'text', minWidth: 100}">采购方式</th>
									<th lay-data="{field:'departmentId', sort: true, edit: 'text'}">采购部门ID</th>
									<th lay-data="{field:'department', sort: true, edit: 'text', minWidth: 100}">采购部门</th>
									<th lay-data="{field:'budget', sort: true, edit: 'text', minWidth: 100}">预算</th>
									<th lay-data="{field:'announceDate', sort: true, edit: 'text', minWidth: 100}">采购公告时间</th>
									<th lay-data="{field:'openDate', sort: true, edit: 'text', minWidth: 100}">开标时间</th>
									<th lay-data="{field:'address', sort: true, edit: 'text', minWidth: 100}">开标地点</th>
									<th lay-data="{field:'dealDate', sort: true, edit: 'text', minWidth: 100}">成交公告时间</th>
									<th lay-data="{field:'url', sort: true, edit: 'text', minWidth: 100}">公告发布网址</th>
									<th lay-data="{field:'dealCompany', sort: true, edit: 'text', minWidth: 100}">成交单位</th>
									<th lay-data="{field:'settlePrice', sort: true, edit: 'text', minWidth: 100}">成交价</th>
									<th lay-data="{field:'linkMan', sort: true, edit: 'text'}">项目联系人姓名</th>
									<th lay-data="{field:'mobliePhone', sort: true, edit: 'text'}">项目联系人电话</th>
									<th lay-data="{field:'createBy', sort: true, edit: 'text'}">创建者</th>
									<th lay-data="{field:'createDate', sort: true, edit: 'text'}">创建时间</th>
									<th lay-data="{field:'updateBy', sort: true, edit: 'text'}">修改者</th>
									<th lay-data="{field:'updateDate', sort: true, edit: 'text'}">修改时间</th>
									<th lay-data="{field:'registerTime', sort: true, edit: 'text'}">报道时间</th>
									<th lay-data="{field:'registerAddress', sort: true, edit: 'text'}">报道地点</th>
									<th lay-data="{field:'committee', sort: true, edit: 'text'}">评标委员会组成人数</th>
									<th lay-data="{field:'professional', sort: true, edit: 'text'}">采购代表</th>
									<th lay-data="{field:'status', sort: true, edit: 'text'}">状态（0未完成1已完成）</th>
									<th lay-data="{templet:'#newsListBar' ,minWidth:190}">操作</th>
							</thead>
						</table>
					</div>-->
					<div class="layui-card-body">
						<table id="projectList" lay-filter="projectList"></table>
					</div>
				</div>
			</div>
		</div>
	</div>
</body>
		<script type="text/html" id="toolbarList">
        <div class = "layui-btn-container" >
			<button class = "layui-btn layui-btn-sm" lay-event = "addNewUser" ><i class="layui-icon">&#xe654;</i>添加用户</button>
			<button class = "layui-btn layui-btn-sm" lay-event = "delBatch" > 批量删除 </button>
			<button class = "layui-btn layui-btn-sm" lay-event = "getCheckData" > 获取选中行数据 </button>
            <button class="layui-btn layui-btn-sm" lay-event="getCheckLength">获取选中数目</button >
            <button class = "layui-btn layui-btn-sm" lay-event = "isAll" > 验证是否全选</button>
        </div >
    </script>
    <!--操作-->
	<script type="text/html" id="newsListBar">
		<a class="layui-btn layui-btn-xs" id="edit" lay-event="edit">编辑</a>
		<a class="layui-btn layui-btn-xs layui-btn-danger" id="del" lay-event="del">删除</a>
		<a class="layui-btn layui-btn-xs layui-btn-primary" id="look" lay-event="look">详情</a>
		<a class="layui-btn layui-btn-xs layui-btn-primary" id="workhistory" lay-event="look">工作历史</a>
		<a class="layui-btn layui-btn-xs layui-btn-primary" id="enrollProj" lay-event="look">参与项目</a>
		<a class="layui-btn layui-btn-xs layui-btn-primary" id="exportToWord" target="_blank" lay-event="exportToWord">导出为word</a>
	</script>

<script>
	layui.use('laydate', function() {
		var laydate = layui.laydate;
		//执行一个laydate实例
		laydate.render({
			elem : '#openDate' //指定元素
            ,trigger: 'click'
		});

	});
</script>
<script>
        layui.use(['form','layer','laydate','table','laytpl'],function(){
            var form = layui.form,
                layer = parent.layer === undefined ? layui.layer : top.layer,
                $ = layui.jquery,
                laydate = layui.laydate,
                laytpl = layui.laytpl,
                table = layui.table;

        //项目列表
        var tableIns = table.render({
            elem: '#projectList',
            url :'projectSearch',
            cellMinWidth : 95,
            page : true,
          //  height : "full-125",
            limit : 10,
            limits : [10,15,20,25],
            id : "projectListTable",
            toolbar:"#toolbarList",
            cols : [[
                {type: "checkbox", fixed:"left", width:50},
                {field: 'id', title: '编号', width:60, align:"center"},
                {field: 'projectName', title: '名称', align:'center'},
                {field: 'projectCategory', title: '类型', align:'center'},
                {field: 'department', title: '采购部门',  align:'center'},
                {field: 'budget', title: '采购预算(万元)', align:'center'},
                {field: 'address', title: '开标地点', align:'center', minWidth:110},
                {field: 'isEvaluated', title: '项目状态', align:'center', minWidth:110,templet:function (data) {
                        if(data.isEvaluated=="1")
                            return "待抽签";
                        else if(data.isEvaluated=="2"){
                            return "随机抽签中";
                        }
                        else if(data.isEvaluated=="3"){
                            return "补抽中";
                        }
                        else if(data.isEvaluated=="4"){
                            return "抽签已完成";
                        }else if(data.isEvaluated=="5"){
                            return "登记成功";
                        }else{//
                            return data.isEvaluated;
                        }
                    }},
                {field: 'openDate', title: '开标时间', align:'center', minWidth:140},
                /* {field: 'announceDate', title: '公告时间', align:'center', minWidth:110},
                 {field: 'openDate', title: '开标时间', align:'center', minWidth:110},

                 {field: 'dealDate', title: '开标公告时间', align:'center', minWidth:110},*/
                /* {field: 'dealCompany', title: '成交单位', align:'center', minWidth:110},
                 {field: 'settlePrice', title: '成交价格', align:'center', minWidth:110},*/
                {title: '操作', minWidth:470,fixed:"right",align:"left", templet:function(data){
                        var str='<a class="layui-btn layui-btn-xs layui-btn-primary" lay-event="look">详情</a>';
                        str+='<a class="layui-btn layui-btn-xs layui-btn-primary" lay-event="professor">专家</a>';
                        str+='<a class="layui-btn layui-btn-xs layui-btn-primary" lay-event="exportToWord">导出为word</a>';

                        if(data.status==1)
                            return str;

                        if(data.isEvaluated=='1'||data.isEvaluated=='待抽签'){
                            str+='<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>';
                            str+='<a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del">删除</a>';
                        }

                        var array=['1','2','3','待抽签','随机抽签中','补抽中'];

                        var sin=array.some(function(elt) {
                            return elt==data.isEvaluated;
                        });
                        //alert(sin);
                        if(sin){
                            str+='<a class="layui-btn layui-btn-xs layui-btn-primary" lay-event="selectProfessor">抽取专家</a>';
                        }
                        var dateStr=new Date().toLocaleDateString();
                        if((data.isEvaluated=='4'||data.isEvaluated=='抽签已完成') &&data.openDate<=dateStr){
                            str+='<a class="layui-btn layui-btn-xs layui-btn-primary" lay-event="inputSettle">中标信息</a>';
                        }
                        return str;
                    }}
                /*{title: '操作', width:250, templet:'#projectListBar',fixed:"right",align:"center"}*/
            ]]
        });





        //搜索【此功能需要后台配合】
        form.on("submit(sreach)",function(data){

            table.reload("projectListTable", {
                page : {
                    curr : 1
                    //重新从第 1 页开始
                },
                where : {
                    projectName : $("input[name=name]").val(), //搜索的关键字
                    projectCategory : $("input[name=category]").val()
                }
            });
            return false;
        });
        //监听单元行
            table.on('tool(projectList)', function(obj){
                var layEvent = obj.event,
                    data = obj.data;//行

               // alert(layEvent);

            if (layEvent == "edit") {
                edit(data);
            } else if (layEvent == "look") {
                look(data);
            } else if (layEvent == "del") {
                del(data);
            } else if(layEvent === 'selectProfessor'){
                var array=['1','2','3','待抽签','随机抽签中','补抽中'];
                var sin=array.some(function(elt) {
                    return elt==data.isEvaluated;
                });
                if(sin){
                    selectProfessor(data);
                }
            } else if(layEvent === 'professor'){
                search(data);
            } else if(layEvent === 'inputSettle'){
                inputSettle(data);
            }
            event.stopPropagation();
            //return false;
        });
        //再添加一个点击监听事件，防止因为按钮过多， 省略号隐藏的按钮没有事件
        table.on('row(queryTable)', function (obj) {
            var data = obj.data;

            $(document).on("click", "#edit", function (event) {
                edit(data);
                event.stopPropagation();//阻止事件冒泡，防止多次执行
                return false;
            });

            $(document).on("click", "#look", function () {
                look(data);
                event.stopPropagation();//阻止事件冒泡，防止多次执行
                return false;
            });
            $(document).on("click", "#del", function () {
                var d = [data];//封装成数组
                deleteAll(d);//
                event.stopPropagation();//阻止事件冒泡，防止多次执行
                return false;
            });
            return false;
        });

        function edit(data) {
            var id = data.id;
            //alert(id);
			xadmin.open('修改用户', './project-edit.html?' + id, 600, 400);
        }
        function look(data) {
                var id = data.id;
               // alert(JSON.stringify(data));
                xadmin.open('修改用户', './project-look.html?' + id, 600, 400);
		}

		//监听单元格编辑，useless
		table.on('edit(projectList)', function(obj) {
			var value = obj.value //得到修改后的值
			, data = obj.data //得到所在行所有键值
			, field = obj.field; //得到字段
			layer.msg('[ID: ' + data.id + '] ' + field + ' 字段更改为：' + value);
		});

            //查询专家列表
          function search(edit){
				alert(JSON.stringify(edit))
              sessionStorage.setItem("Current-Project",JSON.stringify(edit));

                var index = layui.layer.open({
                    title : "查询专家",
                    type : 2,
                    content : "project-professorSearch.html?"+edit.id,
                    success: function(layero, index){
                        console.log(layero, index);
                    }
                });
                layui.layer.full(index);
                //改变窗口大小时，重置弹窗的宽高，防止超出可视区域（如F12调出debug的操作）
                $(window).on("resize", function() {
                    try{
                        layui.layer.full(index);
                    }catch(e){}
                })
            }
            function selectProfessor(data){
                window.sessionStorage.setItem("project",JSON.stringify(data));
                xadmin.open('抽取专家','selectProfessor.html?'+data.id,600,400,true);

            }
            function inputSettle(data){
                //偷懒了，最好open一个窗口完成填写
                layer.prompt({formType:2,title:"请输入中标企业信息",area: ['300px', '240px'],btn:['确认','关闭']
                    ,content:('<label>中&nbsp;&nbsp;标&nbsp;&nbsp;企&nbsp;&nbsp;业</label><input name="dealCompany" id="dealCompany"/><br/><label>中标价(万元)</label><input type="number" id="settlePrice" name="settlePrice"/>')
                    ,yes:function (index,layero) {
                        //alert(JSON.stringify(layero)+"????????????"+layero.find("#dealCompany").val());
                        var c=layero.find("#dealCompany").val();
                        var money=layero.find("#settlePrice").val();
                        alert(c+"><>>>>"+money+"万元：：");
                        $.post("inputSettle",{dealCompany:c,settlePrice:money,projid:data.id},function(d){
                            alert(JSON.stringify(d));
                            if(d){
                                //location.reload();
                                //table.reload("projectListTable");
                                layer.msg("请刷新查看效果!");
                            }else{
                                layer.msg("修改失败!");
                            }
                        });
                        layer.close(index);
                    }
                    ,no:function (index,layero) {
                        layer.close(index);
                    }
                });
            }

		function deleteAll(data){
            if (data.length == 0) {
                return;
            }
		    var ids=[];
            for (var i in data) {
                //isEvaluated=待抽签才可删除
				if (data[i].isEvaluated=="待抽签") {
                ids.push(data[i].id);
            }
            else {
                    alert("ID为("+data[i].id+")的项目的项目状态为("+data[i].isEvaluated+"),不能删除！");
				}}
            if (ids.length!=0){
            layer.confirm('确定删除选中的用户？(非待抽签的项目不能删除！)', {
                icon : 3,
                title : '提示信息'
            }, function(index) {
                $.getJSON("batchDelProject", {ids:ids}, function(d) {
                    if (d>0) {
                        layer.alert("删除成功");
                        location.reload();
                    } else {
                        layer.alert("删除失败");
                    }
                },"text");
            })
            }else {
                alert("非待抽签的项目不能删除！")
			}
			}
		//头工具栏事件
		table.on('toolbar(projectList)', function(obj) {
			var checkStatus = table.checkStatus(obj.config.id);
			switch (obj.event) {
			case 'addNewUser':
				xadmin.open('添加用户','./project-add.html',600,400);
			break;
                //批量删除
                case 'delBatch':
                    var data = checkStatus.data;
                    //layer.alert(JSON.stringify(data));
                    deleteAll(data);
                    break;
                case 'getCheckData':
                    var data = checkStatus.data;
                    layer.alert(JSON.stringify(data));
                    break;
                case 'getCheckLength':
                    var data = checkStatus.data;
                    layer.msg('选中了：' + data.length + ' 个');
                    break;
                case 'isAll':
                    layer.msg(checkStatus.isAll ? '全选' : '未全选');
                    break;
            }
			;
		});
	});
</script>

</html>